/*
 * Copyright 2011 Stefan Ferstl
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.debmavenplugin.common;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

/**
 * Writes a string to a specified file in a specified encoding.
 */
public class StringToFileWriter {

  private final String string;
  private final String encoding;
  private final File outputFile;

  /**
   * Constructor.
   * @param file The file to write a string.
   * @param string The string to write.
   * @param encoding The encoding to use for the file.
   */
  public StringToFileWriter(File file, String string, String encoding) {
    this.outputFile = file;
    this.string = string;
    this.encoding = encoding;
  }

  /**
   * Writes the file.
   * @throws IOException In case of an error.
   */
  public void createFile() throws IOException {
    FileUtils.writeStringToFile(this.outputFile, this.string, this.encoding);
  }
}
